<template>
  <div
    @click="visible = false"
    class="jy-style-height research-box"
    :style="{
      background: `url(${
        publicUrls + 'free/style17/publicStyle17Bg.png' + '?imageView2/3/format/webp'
      }) no-repeat center/100% 100%`,
    }"
  >
    <div class="research-heard">
      <img class="backHome" @click="blankHome" :src="publicUrls + 'free/style17/backHome.png'" alt="" />
      <div class="heard-title">
        <p>学术研究</p>
        <img :src="publicUrls + 'free/style17/otherTitleBg.png'" alt="" />
      </div>
      <div
        class="heard-right"
        @click.stop="visible = !visible"
        :style="list.length === 0 && parmas.typeId === 0 ? { opacity: '0', cursor: 'default' } : { opacity: '1' }"
      >
        <span>{{ TypeTitle }}</span>
        <i class="doorIcon" v-if="!visible">&#xe63a;</i>
        <i class="doorIcon" v-else>&#xe63e;</i>
        <div
          class="menu-box"
          :class="{ 'menu-box-active': visible }"
          :style="{ 'min-width': store.isMobileType ? '80px' : '60px' }"
        >
          <div
            :class="{ 'item-active': parmas.typeId === 0 }"
            class="pop-item pop-item-0 hw-click-cursor"
            @click.stop="setTypeId(0)"
          >
            <span>全部 </span>
          </div>
          <div
            :class="{ 'item-active': parmas.typeId === item.id }"
            class="pop-item hw-click-cursor"
            @click.stop="setTypeId(item)"
            v-for="item in props.selectList"
            :key="item.id"
          >
            <span>
              {{ item.text }}
            </span>
          </div>
        </div>
      </div>
    </div>
    <div class="content-bg">
      <scrollBox color="rgba(50, 43, 37, 1)" v-if="scrollheight && !loading" :byid="986276" :width="getScrollHeight">
        <template #solidBorderCon>
          <div class="researches-list" ref="scrollContainers" @scroll="handleScroll">
            <div class="is-null" v-if="list.length === 0 && !loading">
              <p>暂无学术研究</p>
            </div>
            <div
              class="item"
              v-else
              v-for="item in list"
              :key="item.id"
              :class="!store.isMobileType && 'item-hover'"
              @click="pathInfo(item.id)"
            >
              <div class="item-left">
                <div class="title1">
                  <div v-if="item.typeId" class="title1-color">
                    【
                    {{
                      item.typeId == 401792425939013
                        ? '课题研究'
                        : item.typeId == 401792277585989
                        ? '出版刊物'
                        : '论文论著'
                    }}
                    】
                  </div>
                  <div class="title1-names">{{ item.name }}</div>
                </div>
                <p v-if="item.author" class="title3">{{ item.author }}</p>
              </div>
              <div class="item-right">
                <span v-if="item.publishedOn" class="title2">{{ item.publishedOn }}</span>
                <p v-if="item.publisher" class="title4">{{ item.publisher }}</p>
              </div>
            </div>
          </div>
        </template>
        <template #solidBorderEx>
          <div class="solidBorder-child"></div>
        </template>
      </scrollBox>
    </div>
    <div class="content-door">
      <i class="iconfonts">&#xe6dd;</i>
      <span>永不落幕的展览与展示平台</span>
    </div>
  </div>
  <MenuNavigation />
</template>

<script lang="ts">
export default defineComponent({
  name: 'style17',
});
</script> 

<script setup lang="ts">
import MenuNavigation from '@/freeComponents/menuNavigation/index.vue';
import { publicUrls } from '@/utils/minxin';
import { treeList } from '@/api/user/user';
import RightMenu from '../components/rightMenu.vue';
import Logo from '../components/logo.vue';
import FooterHome from '../components/footerHome.vue';
import PublicTitle from '../components/PublicTitle.vue';
import { useRouter, useRoute } from 'vue-router';
import { ref, watch, reactive, onActivated, nextTick, computed, defineComponent } from 'vue';
import { copyrightSave, copyrightInfo } from '@/api/templates/templates';
import { useProjectStore, commonDataStore } from '@/store';
import { storeToRefs } from 'pinia';
import scrollBox from '../scrollBox.vue';
import { investigationList } from '@/api/investigation/investigation';

const props = defineProps({
  selectList: {
    type: Object,
  },
});
const scrollNumber = ref(0);
const heartbeat = ref(0); //页面心跳值
const store = useProjectStore();
const router = useRouter();
const scrollheight = ref();
const route = useRoute();
const current = ref(1);
const pageSize = ref(20);
const types = ref(true);
const visible = ref(false);
const parmas = reactive({
  value: '',
  pageNo: 1,
  pageSize: 20,
  typeId: 0,
});
const TypeTitle = ref('全部');
const list = ref([]);
const total = ref(0);
const loading = ref(false);
const scrollContainers = ref(null);

let viewportheight = window.innerHeight;
scrollheight.value = (viewportheight / 900) * 520;

const getScrollHeight = computed(() => {
  let rootNode = document.documentElement;

  // 获取计算后的样式
  let computedStyle = window.getComputedStyle(rootNode);

  // 读取字体大小（注意这里返回的可能是一个包含单位的字符串，如"16px"）
  let fontSize = computedStyle.fontSize;

  // 如果你需要一个数字值（不带单位）进行计算，你可能需要解析这个字符串
  // 例如，使用正则表达式或split()方法去除单位，并将结果转换为数字
  let fontSizeNumber = parseFloat(fontSize.replace(/[^0-9.-]/g, ''));
  let heights = (fontSizeNumber / 144) * 520;
  return heights;
});

const init = async (e?: number) => {
  try {
    if (loading.value) {
      return;
    }
    loading.value = true;
    let res = await investigationList(localStorage.getItem('projectId'), parmas);
    total.value = res.data.total;
    if (e) {
      list.value = [];
    }
    list.value = list.value.concat(res.data.data);
    loading.value = false;
    console.log(list.value);
  } catch {
    loading.value = false;
  }
};
const pageWheel = (event: any) => {
  //滚动
  const delta = Math.sign(event.wheelDelta || -event.detail);
  console.log(delta);
  if (delta > 0) {
    scrollContainers.value.scrollTop = scrollContainers.value.scrollTop - 50;
  } else {
    scrollContainers.value.scrollTop = scrollContainers.value.scrollTop + 50;
  }
  event.preventDefault();
  // rightScroll
};
const setTypeId = (e: any) => {
  if (e === 0) {
    parmas.typeId = 0;
    TypeTitle.value = '全部';
  } else {
    parmas.typeId = e.id;
    TypeTitle.value = e.text;
  }
  visible.value = false;
  parmas.pageNo = 1;
  init(2);
};
const handleScroll = () => {
  //滚动加载逻辑

  const scrollContainer = scrollContainers.value;
  const distanceToBottom = scrollContainer.scrollHeight - (scrollContainer.scrollTop + scrollContainer.clientHeight);
  scrollNumber.value = scrollContainer.scrollTop;
  if (distanceToBottom <= 50 && !loading.value && list.value.length < total.value) {
    parmas.pageNo = parmas.pageNo + 1;
    init();
  }
};
const pathInfo = (e: number) => {
  //查看详情
  router.push({
    name: route.meta.loopType ? 'templateresearchLoop' : 'templateresearch',
    query: {
      id: e,
    },
  });
};
init();
onActivated(() => {
  // heartbeat.value
  visible.value = false;
  loading.value = true;
  nextTick(() => {
    loading.value = false;
  });
  if (heartbeat.value !== store.heartbeatCurrent) {
    scrollContainers.value.scrollTop = 0;
    scrollNumber.value = 0;
    parmas.typeId = 0;
    TypeTitle.value = '全部';
    parmas.pageNo = 1;
    init(2);
  } else {
    nextTick(() => {
      scrollContainers.value.scrollTop = scrollNumber.value;
    });
  }
  heartbeat.value = store.heartbeatCurrent;
});
const blankHome = () => {
  router.push({ name: route.meta.loopType ? 'exhibitionHome' : 'templateedit' });
};
</script>

<style scoped lang="less">
.research-box {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 40px 0;
  padding-top: 118px;
  padding-bottom: 0px;
  overflow: hidden;
}

// 头部
.research-heard {
  width: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  padding: 0 76px;
  // 返回按钮
  .backHome {
    cursor: pointer;
    width: 32px;
    height: 32px;
    position: absolute;
    left: 56px;
    top: 50%;
    transform: translateY(-50%);
  }
  // 标题
  .heard-title {
    width: 350px;
    height: 67px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    ::v-deep p {
      font-family: SourceHanSerifCN-Bold;
      font-size: 36px;
      color: #fed681;
      line-height: 67px;
      margin: 0 8px;
      position: relative;
      z-index: 1;
    }
    img {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
    }
  }
  // 筛选按钮
  .heard-right {
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    position: absolute;
    right: 76px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 223;
    span {
      font-family: PingFang SC;
      font-size: 20px;
      line-height: 24px;
      flex-shrink: 0;
      color: rgba(254, 214, 129, 0.8);
    }
    .doorIcon {
      font-size: 14px;
      line-height: 24px;
      color: rgba(254, 214, 129, 0.8);
      margin-left: 4px;
    }
    // 弹窗
    .menu-box {
      width: 96px;
      min-width: 96px;
      height: 0px;
      display: flex;
      flex-direction: column;
      align-items: center;
      position: absolute;
      top: 36px;
      left: 50%;
      transform: translateX(-50%);
      border-radius: 6px;
      background: #fffaee;
      overflow: hidden;
      z-index: 223;
      & > div:first-child {
        margin-top: 0;
      }
      // 选中样式
      .item-active {
        position: relative;
        color: rgba(127, 26, 16, 0.5);
        border-radius: 4px;
        background: rgba(127, 26, 16, 0.15);
        ::v-deep span {
          color: rgba(127, 26, 16, 0.8) !important;
        }
        .solider {
          opacity: 1;
          background: rgba(127, 26, 16, 0.5);
        }
      }
      // 未选中及hover样式
      .pop-item {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 90%;
        height: 32px;
        margin-top: 8px;
        font-family: PingFang SC;
        line-height: 24px;
        flex-shrink: 0;

        span {
          position: relative;
          font-size: 16px;
          color: rgba(127, 26, 16, 0.5);
        }
      }
      .pop-item:hover {
        background: #fcfbfa;
        color: rgba(127, 26, 16, 0.5);
        span {
          color: rgba(127, 26, 16, 0.5);
        }
        // text-decoration: underline;
        .solider {
          opacity: 1;
        }
      }
      // 下划线
      .solider {
        opacity: 0;
        position: absolute;
        left: 0;
        bottom: 1px;
        width: 100%;
        height: 1px;
        background: rgba(255, 255, 255, 0.6);
      }
    }
    // 弹窗显示
    .menu-box-active {
      height: auto;
      padding: 8px 0px;
    }
  }
}

// 内容
.content-bg {
  width: calc(100% - 120px);
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  // 学术列表
  .researches-list {
    width: 100%;
    &::-webkit-scrollbar {
      display: none;
    }
    // 空状态样式
    .is-null {
      width: 100%;
      height: auto;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      position: fixed;
      top: 50%;
      left: 0;
      transform: translate(0, -50%);
      ::v-deep p {
        font-size: 16px;
        color: rgba(255, 227, 162, 0.9);
        line-height: 22px;
        text-indent: 0;
        margin-top: 80px;
      }
    }
    // 列表样式
    .item {
      cursor: pointer;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      width: 100%;
      height: 58px;
      transition: all 0.3s ease;
      position: relative;
      margin-bottom: 30px;

      &:last-child {
        margin-bottom: 0;
      }
      .item-left {
        display: flex;
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        // 标题
        .title1 {
          width: 100%;
          display: flex;
          align-items: center;
          .title1-color {
            font-family: SourceHanSerifCN-Bold;
            font-size: 17px;
            color: #fed681;
            line-height: 32px;
          }
          .title1-names {
            text-align: left;
            max-width: calc(100% - 368px);
            font-family: SourceHanSerifCN-Bold;
            font-size: 17px;
            color: rgba(254, 214, 129, 0.8);
            line-height: 32px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
        // 出版人
        .title3 {
          width: 250px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-family: SourceHanSerifCN;
          font-size: 17px;
          line-height: 32px;
          color: rgba(254, 214, 129, 0.8);
          text-align: right;
          margin-bottom: 0 !important;
          flex-shrink: 0;
        }
      }
      .item-right {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        // 时间
        .title2 {
          font-weight: 400;
          font-size: 14px;
          color: rgba(254, 214, 129, 0.8);
          line-height: 26px;
          opacity: 0.5;
        }
        .title4 {
          width: 250px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-size: 14px;
          line-height: 26px;
          color: rgba(254, 214, 129, 0.8);
          text-align: right;
          margin-bottom: 0 !important;
          opacity: 0.5;
        }
      }
    }
  }
  // 滚动条轨道
  .solidBorder-child {
    width: 1px;
    height: 100%;
    background: #cfc5b9;
    border-radius: 2px;
  }
  ::v-deep .solid-box-parent-p {
    display: none;
  }
  ::v-deep .unit-exbi-remarks-info-remarks {
    width: 100%;
  }
  // 滚动条按钮
  :deep(.templatestyle1-scroll-box-tumb) {
    display: flex;
    align-items: center;
    left: 10px;
    img {
      width: 24px !important;
      height: 16px !important;
      margin-top: -23px;
    }
  }
}

// 底部logo
.content-door {
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 8px;
  background: rgba(70, 23, 7, 0.5);
  .iconfonts {
    font-size: 26px;
    background: linear-gradient(270deg, #e7a859 0%, #ffdaac 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 32px;
  }
  span {
    font-family: PingFang SC;
    font-size: 16px;
    line-height: 32px;
    background: linear-gradient(270deg, #e7a859 0%, #ffdaac 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-left: 20px;
  }
}
</style>